package com.qingjiang.projectschedule.controller;

import com.qingjiang.projectschedule.pojo.dto.ProjectNodeDelayReasonDTO;
import com.qingjiang.projectschedule.pojo.statistic.ProjectExecution;
import com.qingjiang.projectschedule.pojo.statistic.ProjectLag;
import com.qingjiang.projectschedule.pojo.statistic.ProjectLagList;
import com.qingjiang.projectschedule.service.ProjectInformationService;
import com.qingjiang.projectschedule.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: yyg
 * @date: 2024/3/22
 */
@RestController
@RequestMapping("statistic")
@CrossOrigin
public class StatisticController {
    @Autowired
    private ProjectInformationService informationService;

    @GetMapping("getProjectStatisticByYearAndMonth")
    public Result getProjectStatisticByYearAndMonth(@RequestParam("year") Integer year, @RequestParam("month") Integer month) {
        System.out.println("asdfasdfsd");
        return informationService.getProjectStatisticByYearAndMonth(year, month, false);
    }

    @GetMapping("getAllProjectByColor")
    public Result getAllProjectByColor(@RequestParam("deptId") Integer deptId, @RequestParam("year") Integer year, @RequestParam("month") Integer month, @RequestParam("color") String color) {
        List<Map<String, Object>> allProjectByColor = informationService.getAllProjectByColor(deptId, year, month, color);
        return Result.ok(allProjectByColor);
    }

    @PostMapping("updateDelayReason")
    public Result updateDelayReason(@RequestBody List<ProjectNodeDelayReasonDTO> dtos){
//        dtos.forEach(System.out::println);
        informationService.updateDelayReason(dtos);
        return Result.ok("保存成功");
    }

    @GetMapping("projectExecution")
    public Result projectExecution() {
        List<ProjectExecution> result = informationService.queryProjectExecution();
        return Result.ok(result);
    }

    @GetMapping("projectLag")
    public Result projectLag() {
        List<ProjectLag> result = informationService.queryProjectLag();
        return Result.ok(result);
    }

    @GetMapping("projectLagList")
    public Result projectLagList() {
        List<ProjectLagList> result = informationService.queryProjectLagList();
        return Result.ok(result);
    }

    @GetMapping("exportProjectByColor")
    public void exportProjectByColor(@RequestParam("year") Integer year,
                                     @RequestParam("month") Integer month,
                                     @RequestParam("color") String color,
                                     @RequestParam("roleId") Integer roleId,
                                     @RequestParam("deptId") Integer deptId,
                                     HttpServletResponse response) throws IOException {
        System.out.println("year:" + year);
        informationService.exportProjectByColor(year, month, color, roleId, deptId, response);
    }
}
